<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>常用内置对象</h1>

<script>
    //1.Number对象
    /*
    let n1 = 100; //number类型
    let n2 = new Number(100); //对象类型。

    let num = 100.489;
    let s1 = "500";
    let s2 = "abc";

    console.info(num);

    console.info(n1);
    console.info(typeof(n1));
    console.info(n2);
    console.info(typeof(n2));
    console.info(n2.valueOf()); //因为的对象类型，可以调用valueOf().
    console.info(Number.MAX_VALUE);
    console.info(Number.MIN_VALUE);

    console.info(Number(s1)); //强制转换为数字
    console.info(Number(s2));//强制转换为数字
    console.info(num.toLocaleString());
    console.info(num.toFixed(1)); //遵循四舍五入。
    console.info(-100/0);//负无穷大*/


    //2.Math对象
    console.info(Math.abs(-10)); //绝对值
    console.info(Math.sqrt(25)); //平方根
    console.info(Math.pow(2,10)); //2的十次方

    console.info(Math.round(3.99999)); //取整
    console.info(Math.round(3.49999));

    //生成10个1-100之间的随机数
    console.log("生成10个1-100之间的随机数");
    for(let i=0;i<10;i++){
        console.info(parseInt(Math.random()*1000)%100+1);
    }

    //3.Date对象

    let d = new Date();
    let year = d.getFullYear(); //获得年份
    console.info(year);
    let month = d.getMonth(); //获得月份，注意从0开始
    console.info(month);
    let date = d.getDate(); //获得日期
    console.info(date);
    let day = d.getDay(); //获得星期几
    console.info(day);
    let hours = d.getHours(); //获得小时
    console.info(hours);
    let minutes = d.getMinutes();
    let seconds = d.getSeconds();
    console.info(year+"年"+(month+1)+"月"+date+"日  "+hours+":"+minutes+":"+seconds);
    console.info(d.toLocaleDateString());
    console.info(d.toLocaleString());

    //4.RegExp对象
    let email = "32432341@qq"; //合法的。
    let reg = new RegExp("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");
    if(reg.test(email)){//用指定的正则表达式对象检查某个字符串对象是否符合该正则表达式，返回布尔类型
        console.info("该电子邮箱合法！")
    }else{
        console.info("该电子邮箱非法！")
    }

</script>
</body>
</html>